<template>
  <el-form-item>
    <el-select v-model="searchType" @change="textChanged(true)" size="small" style="width:120px;">
      <el-option v-for="item in searchTypeList" :key="item.id" :label="item.name" :value="item.id" style="width:160px;"></el-option>
    </el-select>
    <el-input v-model="searchVal" size="small" :placeholder="searchPlh[searchType]" @keyup.enter.native="keyupEnter" @change="textChanged(false)" style="width:184px;"
      :maxlength="24" clearable></el-input>
  </el-form-item>
</template>
<script>
// import { get_gift_type } from "@/api/common/gift.js";
export default {
  name: "DjGiftSearchSelect",
  props: {
    data: {
      type: Object,
      default() {
        return {};
      }
    },
    from: {
      type: Number,
      default: 0
      // 1：供应商，2：中央仓
    },
    usedfor: {
      type: Number,
      default: 0
      // 1:运管系统采购下单，2：采购平台总部下单，3：采购平台总部统配
    }
  },
  data() {
    return {
      searchVal: "",
      searchType: "1",
      searchPlh: {
        "1": "请输入名称",
        "2": "请输入礼品编号",
        "3": "请输入神采编号",
        "4": "请输入国标码"
      },
      searchTypeList: [
        { id: "1", name: "按名称" },
        { id: "2", name: "按礼品编号" },
        { id: "3", name: "按神采编号" },
        { id: "4", name: "按国标码" }
      ]
    };
  },
  created() {},
  methods: {
    keyupEnter() {
      this.$emit("keyupEnter");
    },
    textChanged(isNone) {
      let val = {
        name: "",
        gift_id: "",
        no_obsolete: "",
        gb_code: ""
      };
      if(isNone) {
        this.searchVal = "";
      }
      switch (this.searchType) {
        case "1":
          val.name = this.searchVal;
          break;
        case "2":
          val.gift_id = this.searchVal;
          break;
        case "3":
          val.no_obsolete = this.searchVal;
          break;
        case "4":
          val.gb_code = this.searchVal;
          break;
        default:
          val.name = this.searchVal;
          break;
      }
      this.$emit("change", val);
    }
  }
};
</script>